import math


class Solution(object):
    def encode(self, num):
        """
        :type num: int
        :rtype: str
        """
        if num == 0:
            return ''
        n = int(math.log2(num + 1))
        num = bin(int(num - 2 ** n + 1))
        s = str(num)[2:]
        if len(s) < n:
            prefix = '0' * (n - len(s))
            s = prefix + s
        return s


data = Solution()
num = 107
print(data.encode(num))
